package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseActivity;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OperatingDataActivity extends BaseActivity {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_all)
    TextView tvAll;
    @BindView(R.id.view_all)
    View viewAll;
    @BindView(R.id.relative_all)
    RelativeLayout relativeAll;
    @BindView(R.id.tv_wait)
    TextView tvWait;
    @BindView(R.id.view_wait)
    View viewWait;
    @BindView(R.id.relative_wait)
    RelativeLayout relativeWait;
    @BindView(R.id.tv_wait_goods)
    TextView tvWaitGoods;
    @BindView(R.id.view_wait_goods)
    View viewWaitGoods;
    @BindView(R.id.relative_wait_goods)
    RelativeLayout relativeWaitGoods;
    @BindView(R.id.tv_over)
    TextView tvOver;
    @BindView(R.id.view_over)
    View viewOver;
    @BindView(R.id.relative_over)
    RelativeLayout relativeOver;
    @BindView(R.id.tv_after)
    TextView tvAfter;
    @BindView(R.id.view_after)
    View viewAfter;
    @BindView(R.id.relative_after)
    RelativeLayout relativeAfter;
    @BindView(R.id.view_page)
    ViewPager viewPage;

    private ArrayList<Fragment> fragments;

    @Override
    public void init() {
        fragments = new ArrayList<>();
        fragments.add(OperatingDataFragment.getInstance(OperatingDataFragment.ON_GOING));
        fragments.add(OperatingDataFragment.getInstance(OperatingDataFragment.RETURN_GOOD));
        fragments.add(OperatingDataFragment.getInstance(OperatingDataFragment.COMPLETED));
    }

    @Override
    public void onCreate(Bundle saveInstanceBundle) {
        super.onCreate(saveInstanceBundle);
        setContentView(R.layout.operating_data_activity);
        ButterKnife.bind(this);
        initView();
    }

    @OnClick({R.id.relative_all, R.id.relative_wait, R.id.relative_wait_goods, R.id.relative_over, R.id.relative_after, R.id.img_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.relative_all:
                viewPage.setCurrentItem(0, false);
                break;
            case R.id.relative_wait:
                viewPage.setCurrentItem(1, false);
                break;
            case R.id.relative_wait_goods:
                viewPage.setCurrentItem(2, false);
                break;
            case R.id.relative_over:
                break;
            case R.id.relative_after:
                break;
            case R.id.img_back:
                finish();
                break;
        }
    }

    private void initView(){

        viewPage.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                return fragments.get(i);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });

        viewPage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                releaseView();
                switch (i){
                    case 0:
                        tvAll.setTextColor(ContextCompat.getColor(OperatingDataActivity.this, R.color.home_page_color));
                        viewAll.setVisibility(View.VISIBLE);
                        break;
                    case 1:
                        tvWait.setTextColor(ContextCompat.getColor(OperatingDataActivity.this, R.color.home_page_color));
                        viewWait.setVisibility(View.VISIBLE);
                        break;
                    case 2:
                        tvWaitGoods.setTextColor(ContextCompat.getColor(OperatingDataActivity.this, R.color.home_page_color));
                        viewWaitGoods.setVisibility(View.VISIBLE);
                        break;
                    case 3:
                        tvOver.setTextColor(ContextCompat.getColor(OperatingDataActivity.this, R.color.home_page_color));
                        viewOver.setVisibility(View.VISIBLE);
                        break;
                    case 4:
                        tvAfter.setTextColor(ContextCompat.getColor(OperatingDataActivity.this, R.color.home_page_color));
                        viewAfter.setVisibility(View.VISIBLE);
                        break;
                }

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });

    }

    private void releaseView(){
        tvAll.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        tvAfter.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        tvOver.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        tvWait.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        tvWaitGoods.setTextColor(ContextCompat.getColor(this, R.color.nomal));

        viewAll.setVisibility(View.INVISIBLE);
        viewAfter.setVisibility(View.INVISIBLE);
        viewOver.setVisibility(View.INVISIBLE);
        viewWait.setVisibility(View.INVISIBLE);
        viewWaitGoods.setVisibility(View.INVISIBLE);
    }
}
